package com.ute.chinesechess;

public class Phao extends QuanCo {
	public boolean KiemTra(int i, int j) {

		if (i >= 0 && i <= 9 && j >= 0 && j <= 8) {
			if (i != Hang && j != Cot)
				return false;
			if(BanCo.board[i][j].Phe == this.Phe)
				return false;
			int ct = 0;		//?
			if (BanCo.board[i][j].Trong == false
					&& BanCo.board[i][j].Phe != this.Phe) {
				if (i == Hang && j >= 0 && j <= 8) {
					if (j > Cot) {
						ct = 0;
						for (int k = Cot + 1; k < j; k++) {
							if (BanCo.board[i][k].Trong == false)
								ct++;
						}
					}
					if (j < Cot) {
						ct = 0;
						for (int k = Cot - 1; k > j; k--) {
							if (BanCo.board[i][k].Trong == false)
								ct++;
						}
					}
				}
				if (j == Cot && i >= 0 && i <= 9) {
					if (i > Hang) {
						ct = 0;
						for (int k = Hang + 1; k < i; k++) {
							if (BanCo.board[k][j].Trong == false)
								ct++;
						}
					}
					if (i < Hang) {
						ct = 0;
						for (int k = Hang - 1; k > i; k--) {
							if (BanCo.board[k][j].Trong == false)
								ct++;
						}
					}
				}
				if (ct != 1)
					return false;
				else
					return true;
			}
			if (i == Hang && j >= 0 && j <= 8) {
				if (j > Cot) {
					for (int k = Cot + 1; k < j; k++) {
						if (BanCo.board[i][k].Trong == false)
							return false;
					}
				}
				if (j < Cot) {
					for (int k = Cot - 1; k > j; k--) {
						if (BanCo.board[i][k].Trong == false)
							return false;
					}
				}
			}
			if (j == Cot && i >= 0 && i <= 9) {
				if (i > Hang) {
					for (int k = Hang + 1; k < i; k++) {
						if (BanCo.board[k][j].Trong == false)
							return false;
					}
				}
				if (i < Hang) {
					for (int k = Hang - 1; k > i; k--) {
						if (BanCo.board[k][j].Trong == false)
							return false;
					}
				}
			}
		}
		return true;
	}
}
